import { baseURI } from '../../app/config';
import { Category } from '../../types/category';

const uri: string = baseURI + '/categories';

export function getCategories(): Promise<Category[]> {
  return fetch(`${uri}`)
    .then((res) => res.json())
    .then((categories) => {
      return categories
    })
    .catch((err) => console.log(err));
}

export function getCategoryById(key: number|string): Promise<Category> {
  return fetch(`${uri}?key=${key}`)
    .then((res)  => res.json())
    .then((category) => category[0])
    .catch((err) => console.log(err))
}
